package com.twu.biblioteca.view;

import com.twu.biblioteca.events.Event;
import com.twu.biblioteca.events.Listener;
import com.twu.biblioteca.model.item.ItemID;
import com.twu.biblioteca.presenter.ReservationPresenter;
import com.twu.biblioteca.view.utils.Input;
import com.twu.biblioteca.view.utils.Output;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: cschlumb
 * Date: 08/08/2013
 * Time: 12:17
 * To change this template use File | Settings | File Templates.
 */
public class ReservationView implements ReservationPresenter.Display{

    private final Output output;
    private final Input input;

    private ItemID inputSelection = null;
    private final Event inputEvent = new Event();

    public ReservationView(Output output, Input input) {
        this.output = output;
        this.input = input;
    }

    @Override
    public void prompt(){
        output.write("Please input book ID:");
        inputSelection = getInput();
        inputEvent.fire();
    }

    ItemID getInput(){
        int id = input.readInt();
        return new ItemID(id);
    }

    @Override
    public ItemID getItemSelection(){
        return inputSelection;
    }

    @Override
    public void successMessage() {
        output.write("Thank You! Enjoy the book.");
    }

    @Override
    public void failMessage() {
        output.write("Sorry we don't have that book yet.");
    }

    @Override
    public void addEventListener(Listener listener) {
        inputEvent.addListener(listener);
    }
}
